// 引入 ECharts 主模块
var echarts = require('echarts/lib/echarts')
// 引入柱状图
require('echarts/lib/chart/bar')
require('echarts/lib/chart/line')
// 引入提示框和标题组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
require('echarts/lib/component/legend')
require('echarts/lib/component/grid')
import { parseTime } from '@/utils/index'

const getRandomDataNum = (dayStand: number) => {
  let tempDate = []
  for (let i = 0; i <= dayStand; i++) {
    tempDate.push(Math.ceil(100 * Math.random()))
  }
  return tempDate
}
export default class EchartsConfig {
  private myChart: any
  private option = {
    yAxis: [
      {
        type: 'value'
      },
      {
        type: 'value'
      }
    ],
    xAxis: [
      {
        data: [
          '2019-08-01',
          '2019-08-02',
          '2019-08-03',
          '2019-08-04',
          '2019-08-05',
          '2019-08-06',
          '2019-08-07',
          '2019-08-08',
          '2019-08-09',
          '2019-08-10'
        ],
        type: 'category'
      }
    ],
    grid: {
      left: '3%',
      bottom: '20%',
      right: '4%',
      containLabel: true
    },
    legend: {
      data: ['v1.0 (数量)', 'v3.0 (数量)', 'v1.0通过率', 'v3.0通过率'],
      type: 'scroll'
    },
    color: ['#7EC0EE', '#FF9F7F', '#FFD700', '#C9C9C9', '#E066FF'],
    series: [
      {
        stack: 'stack',
        data: [1034, 936, 857, 1137, 1045, 1099, 834, 915, 945, 989],
        name: 'v1.0 (数量)',
        type: 'bar',
        yAxisIndex: 0
      },
      {
        stack: 'stack',
        data: [517, 468, 428, 568, 522, 549, 417, 457, 472, 494],
        name: 'v3.0 (数量)',
        type: 'bar',
        yAxisIndex: 0
      },
      {
        data: [
          0.80348162475822051,
          0.64423076923076922,
          0.72835472578763127,
          0.52752858399296393,
          0.73301435406698564,
          0.5337579617834395,
          0.845083932853717,
          0.6453551912568306,
          0.89417989417989418,
          0.5455005055611729
        ],
        name: 'v1.0通过率',
        type: 'line',
        yAxisIndex: 1
      },
      {
        data: [
          0.61605415860735009,
          0.51538461538461539,
          0.72383177570093458,
          0.81619718309859155,
          0.53409961685823754,
          0.44754098360655737,
          0.43189448441247004,
          0.60065645514223195,
          0.9885593220338983,
          0.89109311740890688
        ],
        name: 'v3.0通过率',
        type: 'line',
        yAxisIndex: 1
      }
    ],
    toolbox: {
      feature: {
        saveAsImage: {
          name: '策略灰度-通过率对比2019-12-20'
        },
        dataZoom: {},
        dataView: {
          readOnly: true
        }
      },
      top: 'bottom',
      left: 'center',
      show: true
    },
    tooltip: {
      axisPointer: {
        type: 'shadow'
      },
      trigger: 'axis'
    }
  }

  constructor(domId: string) {
    this.myChart = echarts.init(document.getElementById(domId))
  }
  public setOption(data: any) {
    console.log(data)
    this.option = data
    this.myChart.clear()
    this.myChart && this.myChart.setOption(this.option)
  }
}
